<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex grainEditing_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub grainEditing_fd0_0'>
          <view class='flex flex-wrap align-center grainEditing_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  grainEditing_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='grainEditing_fd0_0_c1_c0'>粮站编辑</text>
          </view>
          <view class='flex flex-wrap align-center justify-end grainEditing_fd0_0_c0'>
            <image class='grainEditing_fd0_0_c2_c0' mode="aspectFit" :src='STATIC_URL+"7.png"'></image>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout grainEditing_flex_1">
        <view class='flex flex-direction flex-wrap align-start grainEditing_fd1_0'>
          <text class='grainEditing_fd1_0_c0'>粮站名称</text>
          <benben-input class='flex-sub grainEditing_fd1_0_c1' type="text" :placeholder="`请填写粮站名称`" confirm-type="done"
            v-model="info.mingcheng" :maxlength="-1" placeholder-style="color:#999;font-size:36rpx" />
        </view>
        <view class='flex flex-direction flex-wrap align-stretch grainEditing_fd1_1'>
          <view class='flex flex-wrap align-center justify-between'>
            <text class='grainEditing_fd1_0_c0'>粮站招牌</text>
            <!-- <image class='grainEditing_fd1_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"128.png"'></image> -->
          </view>
          <view class='flex flex-wrap align-center grainEditing_fd1_1_c1'>
            <view class='flex flex-wrap align-center grainEditing_fd1_1_c1_c0'>
              <benben-images-upload ref="benbenImagesUploadfd1_0_c4_c01" :maxlength="1"
                :img-list.sync="info.zhaopaifengmian" :img-ids.sync="img_ids" :is-show-tips='true'>
                <template #content="{ num, maxlength, isShow, imgList }">
                  <view class="flex flex-wrap align-start flex feedBack_fd1_0_c4_c0">

                    <view v-for="(image, index) in imgList" :key="index"
                      class='flex position-relative feedBack_fd1_0_c4_c00'>
                      <text class='fu-iconfont2 position-absolute feedBack_fd1_0_c4_c000'
                        @tap.stop="$refs.benbenImagesUploadfd1_0_c4_c01.delImage(index)">&#xE8E7;</text>
                      <image class='feedBack_fd1_0_c4_c001'
                        @tap.stop="$refs.benbenImagesUploadfd1_0_c4_c01.previewImage(index)" mode="aspectFill"
                        :src='image'>
                      </image>
                    </view>

                    <image class='feedBack_fd1_0_c4_c01'
                      @tap.stop="$refs.benbenImagesUploadfd1_0_c4_c01.manyChooseImage()" v-if="isShow" mode="aspectFit"
                      :src='STATIC_URL+"25.png"'></image>

                  </view>
                </template>
              </benben-images-upload>
            </view>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch grainEditing_fd1_1'>
          <view class='flex flex-wrap align-center justify-between'>
            <text class='grainEditing_fd1_0_c0'>粮站位置</text>
          </view>
          <view class='flex flex-wrap align-center grainEditing_fd1_2_c1' @click.stop="chooseLocation">
            <image class='grainEditing_fd1_2_c1_c0' mode="aspectFit" :src='STATIC_URL+"129.png"'></image>
            <benben-input class='flex-sub grainEditing_fd1_2_c1_c1' type="text" :placeholder="`请选择地址`" disabled
              v-model="info.weizhi" confirm-type="done" :maxlength="-1"
              placeholder-style="color:#999;font-size:36rpx" />
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch grainEditing_fd1_1'>
          <view class='flex flex-wrap align-center justify-between'>
            <text class='grainEditing_fd1_0_c0'>粮站电话</text>
          </view>
          <view class='flex flex-wrap align-center grainEditing_fd1_2_c1'>
            <benben-input class='flex-sub grainEditing_fd1_2_c1_c1' type="number" :placeholder="`请输入手机号`"
              v-model="info.lianxidianhua" confirm-type="done" :maxlength="11"
              placeholder-style="color:#999;font-size:36rpx" />
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch grainEditing_fd1_1' @tap.stop="handleJumpDiy"
          data-type="navigateTo"
          :data-url="`/pages/wode/businessContent/businessContent?type=1&liangzhancate_id=${info.liangzhancate_id}`">
          <text class='grainEditing_fd1_0_c0'>经营种类</text>
          <view class='flex flex-wrap align-center grainEditing_fd1_1_c1'>
            <view class='flex flex-wrap align-center flex-sub'>
              <view class='flex flex-wrap align-center grainEditing_fd1_4_c1_c0_c0'
                v-for="(item,index) in info.liangzhancate_mingcheng" :key="index">
                <text class='grainEditing_fd1_4_c1_c0_c0_c0'>{{item}}</text>
                <image class='grainEditing_fd1_4_c1_c0_c0_c1' mode="aspectFit" :src='STATIC_URL+"131.png"'></image>
              </view>
            </view>
            <image class='grainEditing_fd1_4_c1_c1' mode="aspectFit" :src='STATIC_URL+"130.png"'></image>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch grainEditing_fd1_1' @tap.stop="handleJumpDiy"
          data-type="navigateTo"
          :data-url="`/pages/wode/managemyDevice/managemyDevice?type=1&liangzhanshebeicate_id=${info.liangzhanshebeicate_id}`">
          <text class='grainEditing_fd1_0_c0'>粮站设备</text>
          <view class='flex flex-wrap align-center grainEditing_fd1_1_c1'>
            <view class='flex flex-wrap align-center flex-sub'>
              <view class='flex flex-wrap align-center grainEditing_fd1_4_c1_c0_c0'
                v-for="(item,index) in info.liangzhanshebeicate_mingcheng" :key="index">
                <text class='grainEditing_fd1_4_c1_c0_c0_c0'>{{item}}</text>
                <image class='grainEditing_fd1_4_c1_c0_c0_c1' mode="aspectFit" :src='STATIC_URL+"131.png"'></image>
              </view>
            </view>
            <image class='grainEditing_fd1_4_c1_c1' mode="aspectFit" :src='STATIC_URL+"130.png"'></image>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch grainEditing_fd1_1'>
          <view class='flex flex-wrap align-center justify-between'>
            <text class='grainEditing_fd1_0_c0'>粮站环境</text>
            <!-- <image class='grainEditing_fd1_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"128.png"'></image> -->
          </view>
          <view class='flex flex-wrap align-center grainEditing_fd1_1_c1'>
            <benben-images-upload ref="benbenImagesUploadfd1_0_c4_c0" :maxlength="6"
              :img-list.sync="info.liangzhanhuanjing" :img-ids.sync="img_id" :is-show-tips='true'>
              <template #content="{ num, maxlength, isShow, imgList }">
                <view class="flex flex-wrap align-start flex feedBack_fd1_0_c4_c0">

                  <view v-for="(image, index) in imgList" :key="index"
                    class='flex position-relative feedBack_fd1_0_c4_c00'>
                    <text class='fu-iconfont2 position-absolute feedBack_fd1_0_c4_c000'
                      @tap.stop="$refs.benbenImagesUploadfd1_0_c4_c0.delImage(index)">&#xE8E7;</text>
                    <image class='feedBack_fd1_0_c4_c001'
                      @tap.stop="$refs.benbenImagesUploadfd1_0_c4_c0.previewImage(index)" mode="aspectFill"
                      :src='image'>
                    </image>
                  </view>

                  <image class='feedBack_fd1_0_c4_c01' @tap.stop="$refs.benbenImagesUploadfd1_0_c4_c0.manyChooseImage()"
                    v-if="isShow" mode="aspectFit" :src='STATIC_URL+"25.png"'></image>

                </view>
              </template>
            </benben-images-upload>
            <!--   <view class='flex flex-wrap align-center grainEditing_fd1_1_c1_c0'>
              <image class='grainEditing_fd1_1_c1_c0_c0' v-for="(item,index) in info.liangzhanhuanjing
" :key="index" mode="aspectFit" :src='item'></image>
            </view> -->
          </view>
        </view>
        <view class='flex flex-wrap align-center justify-center grainEditing_fd1_7'>
          <button class='grainEditing_fd1_7_c0' @tap.stop="submit" data-type="back" data-url="1">确定</button>
        </view>
      </view>

      <!---flex布局flex布局结束-->


    </view>
  </view>
</template>
<script>
  import amapFile from '@/libs/amap-wx.js';
  import {
    validate
  } from '@/common/utils/validate.js';
  export default {
    components: {},


    data() {
      return {
        "aid": "",
        info: {
          zhaopaifengmian: [],
          liangzhanhuanjing: []
        },
        img_ids: '',
        img_id: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      userInfo() {
        return this.$store.state.userInfo
      },
    },
    watch: {},
    onLoad(options) {
      let {
        aid
      } = options
      if (aid !== undefined) this.aid = aid
      this.myAmapFun = new amapFile.AMapWX({
        key: '63259edc296cb943ffc26c92b77eba63'
      });
      this.getDetail()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {
      uni.$on('liangzhancate_arr', data => {
        console.log('liangzhancate_arr', data)
        if (data) {
          this.info.liangzhancate_mingcheng = data.map(item => {
            return item.name
          })
          this.info.liangzhancate_id = data.map(item => {
            return item.aid
          }).join(',')
        }

      })
      uni.$on('liangzhanshebeicate_arr', data => {
        console.log('liangzhanshebeicate_arr', data)
        if (data) {
          this.info.liangzhanshebeicate_mingcheng = data.map(item => {
            return item.name
          })
          this.info.liangzhanshebeicate_id = data.map(item => {
            return item.aid
          }).join(',')
        }

      })
    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      chooseLocation() {
        let _this = this
        uni.chooseLocation({
          success: (resule) => {
            console.log(resule, '地图');
            _this.info.jingdu = resule.longitude
            _this.info.weidu = resule.latitude
            // _this.location_address = resule.name
            _this.myAmapFun.getRegeo({
              location: resule.longitude + ',' + resule.latitude,
              success: (data) => {
                //成功回调
                let regeoData = data[0].regeocodeData.addressComponent;
                // _this.info.chengshi = regeoData.city
                // return;
                _this.info.chengshi = regeoData.city.length ? regeoData.city : '';
                _this.info.shengfen = regeoData.province;
                // _this.info.shengfen = regeoData.district;
                _this.info.weizhi = _this.info.shengfen + _this.info.chengshi +
                  resule.name
              },
              fail: (info) => {
                //失败回调
                console.log('info', info)
              }
            })
          }
        })
      },
      submit() {
        if (!this.info.xingming) {
          this.$message.info('请输入姓名')
          return;
        }
        if (!this.info.lianxidianhua) {
          this.$message.info('请输入联系电话')
          return;
        }
        if (!validate(this.info.lianxidianhua, 'phone')) {
          this.$message.info('请输入正确的手机号');
          return false;
        }
        if (!this.info.mingcheng) {
          this.$message.info('请输入粮站名称')
          return;
        }
        if (this.info.zhaopaifengmian.length == 0) {
          this.$message.info('请上传相关粮站照片')
          return;
        }
        if (this.info.liangzhanhuanjing.length == 0) {
          this.$message.info('请上传相关粮站照片')
          return;
        }
        console.log('ooooo', this.info.weizhi)
        this.info.liangzhanhuanjing = this.info.liangzhanhuanjing.join(',')
        this.info.zhaopaifengmian = this.info.zhaopaifengmian.join(',')
        this.$api.post(global.apiUrls.post65d83e1a961bb, {
          jingdu: this.info.jingdu,
          weidu: this.info.weidu,
          liangzhancate_id: this.info.liangzhancate_id,
          liangzhanshebeicate_id: this.info.liangzhancate_id,
          xingming: this.info.xingming,
          lianxidianhua: this.info.lianxidianhua,
          jingyingnianxian: this.info.jingyingnianxian,
          liangzhanhuanjing: this.info.liangzhanhuanjing,
          zhaopaifengmian: this.info.zhaopaifengmian,
          mingcheng: this.info.mingcheng,
          weizhi: this.info.weizhi,
          chengshi: this.info.chengshi,
          shengfen: this.info.shengfen
        }).then(res => {
          if (res.data.code == 1) {
            // uni.redirectTo({
            //   url: `/pages/wode/mygrainStation/mygrainStation`
            // })
            // return;
            if (res.data.data.is_vip == false) {
              uni.redirectTo({
                url: `/pages/wode/personalinformationSuccessfully/personalinformationSuccessfully?aid=${res.data.data.liangzhan_id}`
              })
            } else {
              console.log('res.data.data111', res.data.data.is_vip)
              uni.navigateBack()
              // uni.redirectTo({
              //   url: `/pages/wode/mygrainStation/mygrainStation`
              // })
            }
          } else {
            this.$message.info(res.data.msg)
          }
        })
      },
      getDetail() {
        this.$api.post(global.apiUrls.post65d84a4c2a9f6, {
          user_id: this.userInfo && this.userInfo.id
        }).then(res => {
          console.log('ressssssss', res.data.code, )
          if (res.data.code == 1) {
            this.info = res.data.data
            this.info.liangzhancate_mingcheng = res.data.data.liangzhancate_mingcheng.split('，')
          }
        })
      },
    }
  };
</script>
<style lang="scss" scoped>
  .feedBack_fd1_0_c4_c01 {
    width: 160rpx;
    height: 160rpx;
    margin: 0rpx 24rpx 24rpx 0rpx;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
  }

  .feedBack_fd1_0_c4_c001 {
    width: 160rpx;
    height: 160rpx;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
  }

  .feedBack_fd1_0_c4_c000 {
    top: 0rpx;
    right: 0rpx;
    z-index: 2;
    color: #ff5536;
  }

  .feedBack_fd1_0_c4_c00 {
    margin: 0rpx 24rpx 24rpx 0rpx;
  }

  .feedBack_fd1_0_c4_c0 {
    padding: 24rpx 0rpx 0rpx 24rpx;
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(255, 255, 255, 1);
    background-size: 100% auto;
  }

  .grainEditing_flex_0 {
    background: rgba(255, 255, 255, 1);
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto;
  }

  .grainEditing_fd0_0_c2_c0 {
    width: 119rpx;
    height: 55rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .grainEditing_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .grainEditing_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .grainEditing_fd0_0_c0 {
    width: 120rpx;
  }

  .grainEditing_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .grainEditing_flex_1 {
    padding: 0rpx 30rpx 40rpx 30rpx;
  }

  .grainEditing_fd1_7_c0 {
    background: rgba(37, 104, 174, 1);
    border-radius: 100rpx;
    width: 686rpx;
    line-height: 88rpx;
    font-size: 34rpx;
    color: #fff;
  }

  .grainEditing_fd1_7 {
    margin: 60rpx 0rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_4_c1_c1 {
    width: 14rpx;
    height: 26rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .grainEditing_fd1_4_c1_c0_c0_c1 {
    width: 32rpx;
    height: 32rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    position: absolute;
    right: 0rpx;
    bottom: 0rpx;
  }

  .grainEditing_fd1_4_c1_c0_c0_c0 {
    color: #2568AE;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .grainEditing_fd1_4_c1_c0_c0 {
    background: rgba(37, 104, 174, 0.2);
    padding: 14rpx 44rpx 14rpx 44rpx;
    background-size: 100% auto;
    border-radius: 6rpx;
    position: relative;
    margin: 10rpx 24rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_2_c1_c1 {
    font-size: 36rpx;
    color: #333;
  }

  .grainEditing_fd1_2_c1_c0 {
    width: 26rpx;
    height: 32rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: -10rpx 24rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_2_c1 {
    margin: 24rpx 0rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_1_c1_c0_c0 {
    width: 200rpx;
    height: 200rpx;
    border-radius: 16rpx;
  }

  .grainEditing_fd1_1_c1_c0 {
    margin: 10rpx 10rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_1_c1 {
    margin: 14rpx 0rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_1_c0_c1 {
    width: 40rpx;
    height: 40rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .grainEditing_fd1_1 {
    border-bottom: 1px solid #eee;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .grainEditing_fd1_0_c1 {
    margin: 24rpx 0rpx 0rpx 0rpx;
    font-size: 36rpx;
    color: rgba(16, 16, 16, 1);
  }

  .grainEditing_fd1_0_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .grainEditing_fd1_0 {
    border-bottom: 1px solid #eee;
    padding: 40rpx 0rpx 32rpx 0rpx;
  }
</style>
